package com.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.ClientBean;
import com.project.service.IClientService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("client")
@Api(tags="客户控制器")
public class ClientController {
    @Autowired
    private IClientService clientService;
    @ApiOperation(value = "动态分页查询客户",notes = "按姓名、经营范围动态分页查询经营范围")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name="pageNO",value = "页码",required = true),
            @ApiImplicitParam(name="name",value = "客户名"),
            @ApiImplicitParam(name="scope",value = "经营范围")
    })
    @RequestMapping("cutByItem")
    @RequiresPermissions("client:*")
    public IPage<ClientBean> cutByItem(Integer pageNO, String name, String scope) {
        return clientService.cutByItem(pageNO, name, scope);
    }
    @ApiOperation(value = "按id查询客户信息")
    @ApiImplicitParam(name="id",value = "编号")
    @RequestMapping("findById")
    public ClientBean findById(Integer id) {
        return clientService.findById(id);
    }

    @ApiOperation(value = "修改客户信息",notes = "id修改客户负责人、电话、经营范围")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name="id",value = "编号",required = true),
            @ApiImplicitParam(name="person",value = "负责人"),
            @ApiImplicitParam(name="phone",value = "负责人电话"),
            @ApiImplicitParam(name="scope",value = "经营范围")
    })
    @RequestMapping("update")
    @RequiresPermissions("client:*")
    public String update(Integer id, String person, String phone, String scope) {
        clientService.update(id, person, phone, scope);
        return "ok";
    }

    @ApiOperation(value = "添加客户对象")
    @RequestMapping("add")
    @RequiresPermissions("client:*")
    public String add(ClientBean client) {
        clientService.add(client);
        return "ok";
    }
    @ApiOperation(value = "查询所有客户")
    @RequestMapping("findAll")
    @RequiresPermissions("client:*")
    public List<ClientBean> findAll(){
      return clientService.findAll();
    }
}
